package com.example.tys.baseapplication.NetModel.okhttp.requset;

import android.support.annotation.NonNull;


import com.example.tys.baseapplication.NetModel.okhttp.OkHttpClientManger;

import java.util.Map;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2016/10/27.
 */
public class PostRequestBuilder extends BaseRequest<PostRequestBuilder> {


    @Override
    public Call build() {
        Request req = new Request.Builder()
                .url(url)
                .headers(addHead(heads))
                .post(addPostParams(params))
                .tag(tag)
                .build();
        return OkHttpClientManger.getClient("").newCall(req);
    }

    private RequestBody addPostParams(@NonNull Map<String, String> params) {
        FormBody.Builder bodyBuilder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            bodyBuilder.add(entry.getKey(), entry.getValue());
        }
        return bodyBuilder.build();
    }





}
